#include <stdlib.h>
#include <stdio.h>

__global__ void add(int a, int b, int* c)
{
    *c = a + b;
}

int main()
{
    cudaError_t error;
    error = cudaGetLastError();
    if (error != cudaSuccess) {
        printf("%s\n", cudaGetErrorString(error));
        return -1;
    }

    int c;
    int *dev_c;
    error = cudaMalloc( (void**)&dev_c, sizeof(int));

    add<<<1,1>>>(2, 7, dev_c);

    error = cudaMemcpy(&c, dev_c, sizeof(int), 
                        cudaMemcpyDeviceToHost);
    printf("2 + 7 = %d\n", c);
    cudaFree(dev_c);
    return 0;
}